Skip to content

hash: measure the table again: Emscripten linked at its optimization level, WASI without debug information - #2

Merged
pinhopro merged 2 commits into
mainfrom
fix/measure-emscripten-link
Nov 16, 2026
Merged

pinhopro merged 2 commits into
mainfrom
fix/measure-emscripten-link

Conversation

@pinhopro

@pinhopro pinhopro commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

The libs/hash half of webcpporg/webcpp#23, which carries the measure.py check.

The measure lane failed on webcpp's main (run 43883027557, job "Own lane (hash, measure)"):

hkdf_extract over hmac_sha2_512 on emscripten: by size hash2, sodium, committed sodium, hash2

Root cause

  1. The failing row was a stale table, not the host. The committed table (2026-11-15) was measured before webcpp PR 18 ("link emscripten programs at their compile's level of optimization") reached the hash branch, so every Emscripten program had been linked at em++'s default -O0. Relinking today's hash2 object without -Os gives the committed 121,510 bytes exactly. Linked at -Os, as main does, hash2 is 21,083 bytes and libsodium 24,591, so hash2 is now the smaller one. The Mac reproduces CI's failure message exactly on main.
  2. A real host dependence, on WASI. WASI programs carried the DWARF of wasi-sdk's prebuilt libc++. That debug information names the paths of the machine that built the wasi-sdk release: /Users/runner/work/wasi-sdk/... in the macOS archive and /src/src/... in the Linux one. The result: 58 of the 146 WASI cells were 128 to 2,000 bytes larger on macOS than in a linux/amd64 container with the same wasi-sdk 34. For example, space-hkdf_extract_hash2_hmac_sha2_256 on wasip2 was 440,872 bytes on macOS and 439,848 on Linux. The debug sections were most of each program: that one is 59,161 bytes without them.

Fix

  • libs/hash test/measure/Jamfile links every WASI program with -Wl,--strip-debug. Emscripten's -Os link keeps no debug section already, and natively the size is the stripped executable.
  • tools/hash/measure.py (--check and --write) reads each WebAssembly program's custom sections, including every core module and component a wasip2 component nests. It fails, naming each program for size that has a .debug* section. The test came first: test_a_webassembly_program_with_debug_information_fails. RULES now says the .wasm carries no debug information.
  • The table was measured again on main with python3 tools/hash/measure.py --write on an idle machine (loaded: false), and the guide's generated tables were rewritten with doc_tables.py --write. Orders that change:
    • Emscripten: by size, hkdf_extract over hmac_sha2_512 is now hash2, sodium. By throughput, libsodium is now ahead of hash2 for hkdf_expand over hmac_sha2_256 and for hkdf over both hmacs; its median is 10.6 to 12.5 percent lower, past spec 4.2's 10 percent.
    • wasip2 and wasip3: by size, libsodium is now ahead of hash2 for hkdf_expand and hkdf, with BearSSL still first for hkdf.

Host independence

  • Emscripten: byte-identical on macOS arm64 and linux/amd64. hkdf_extract over hmac_sha2_512 is 21,083 bytes for hash2 and 24,591 for sodium on both hosts, with the same SHA-256.
  • WASI: sizes are now equal except a 64-byte residual (144 for OpenSSL) in 48 KDF programs. It comes from two __FILE__ strings of wasi-sdk's libc++abi (fallback_malloc.cpp, private_typeinfo.cpp) in the data section. These are real program bytes, so they cannot be stripped. No order can flip on them: the smallest gap between adjacent backends in any WebAssembly order is 1,212 bytes. Removing the residual would take one host-independent wasi-sysroot on every host, which is a toolchain decision outside this change.

Verification

  • Measure lane libs/hash/test/measure//measure, from scratch:
    • macOS: 284 cells agree.
    • linux/amd64 container (CI image, Ubuntu 24.04, Clang 18, the CI's emsdk and wasi-sdk): 284 cells agree; the native orders are skipped with the lane's one line.
    • Before the fix, both hosts failed with CI's message.
  • Tool tests: tools/test/hash_measure_test.py (16 cases) and hash_doc_tables_test.py ok; doc_tables.py --check ok; Pyright clean on both changed files.
  • hash lanes (-a, libs/hash/test and example): native 153 passed, wasip2 151, wasip3 151, Emscripten 118.

Remaining: wasi-sdk's libc++ debug information also inflates every webcpp WASI release program. Whether release links should strip it is a separate decision, not made here. bench/'s doc/measurements.throughput.json was measured before PR 18 as well and was not re-run.

🤖 Generated with Claude Code

…inked at their optimization level

The table of 2026-11-15 was measured on a superproject without webcpp's
"link emscripten programs at their compile's level of optimization"
(webcpp PR 18), so every Emscripten program was linked at em++'s -O0:
space-hkdf_extract_hash2_hmac_sha2_512 was 121,510 bytes, which the same
object relinked without -Os gives byte for byte today. Linked at -Os, as
the superproject's main now links it, it is 21,083 bytes and libsodium's
24,591, so hkdf_extract over hmac_sha2_512 on Emscripten orders hash2
first by size, and the measure lane failed on main.

Measured again with `python3 tools/hash/measure.py --write` on main:
every Emscripten size and throughput changes, wasip2's and wasip3's sizes
do not, and native's change by 16 bytes in one cell (hkdf over
hmac_sha2_256 on BearSSL). The orders that change are Emscripten's:
hkdf_extract over hmac_sha2_512 by size (hash2, sodium), and hkdf_expand
over hmac_sha2_256 and hkdf over both hmacs by throughput (sodium ahead of
hash2, its median now 10.6 to 12.5 percent lower). The default of the smallest profile
on Emscripten for hkdf_extract over hmac_sha2_512 becomes hash2.

The sizes do not depend on the host: the two Emscripten programs built
in a linux/amd64 container with the same Emscripten 6.0.11 are
byte-identical to the macOS arm64 ones (same SHA-256). The generated
tables of the guide are written again from the new data
(tools/hash/doc_tables.py --write).
…ion, whose paths are the host's that built wasi-sdk

A WASI program for size carried the DWARF of wasi-sdk's prebuilt libc++,
which names the include paths of the machine that built the release:
/Users/runner/work/wasi-sdk/... in wasi-sdk 34's macOS archive and
/src/src/... in its Linux one. The same program, built from the same
objects with the same wasi-sdk, was 1,024 bytes larger on macOS than in a
linux/amd64 container (space-hkdf_extract_hash2_hmac_sha2_256 on wasip2:
440,872 and 439,848 bytes), and 58 of the 146 WASI cells differed, by 128
to 2,000 bytes. A WebAssembly order is compared on every host, so a near
tie could flip with the host that measures it; and the debug sections
were most of each program: that program is 59,161 bytes without them.

test/measure/Jamfile links every WASI program with wasm-ld's
--strip-debug (<target-os>wasi:<linkflags>-Wl,--strip-debug). Emscripten's
link at -Os keeps no debug section already, and natively the size is the
stripped executable.

Measured again (`python3 tools/hash/measure.py --write`, an idle machine:
load averages 10.6 before and 5.5 after on 18 cores): every wasip2 and
wasip3 size changes, Emscripten's and native's do not. Without libc++'s
debug information, libsodium is smaller than hash2 for hkdf_expand on
wasip2 and wasip3 (73,410 and 75,028 bytes over hmac_sha2_256), and for
hkdf after BearSSL, so those orders by size, and the default by size of
hkdf_expand on WASI, become libsodium's. No throughput order changes.
@pinhopro pinhopro changed the title hash: measure the table again with Emscripten programs linked at their optimization level hash: measure the table again: Emscripten linked at its optimization level, WASI without debug information Nov 16, 2026
@pinhopro
pinhopro merged commit 46b1989 into main Nov 16, 2026
@pinhopro
pinhopro deleted the fix/measure-emscripten-link branch November 20, 2026 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant